<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<script>
			//VAR  FUNCTION 

			// console.log(abc);

			// var abc;

			
			var mystr = "abc";// window  --- this 


			//声明函数 
			function sayHi() {
				console.log("大家好，我学会了function2")
			}

			sayHi();


			function introduce(name) {
				console.log("大家好，我是:" + name)
			}

			introduce("关羽");
			introduce("张飞");
			introduce("刘备");

			// \r  \n  \t
			function cal(numa, numb) {
				console.log("大家好，我会算数:numa = " + numa + " , numb = " + numb + "   和\t " + (numa + numb))
			}


			function cal2(numa, numb, numc) {
				console.log("三个数字加", numa + numb + numc)

			}
			
			//通过 arguments  获取参数
			function calArguments(numa, numb, numc,numd) {
				
				console.log(arguments);
				let result = 0;
				for (let i = 0; i < arguments.length; i++) {
					result += arguments[i]
				}
				console.log("多个数字相加", result)
			
			}
			
			
			//带返回值
			function sum(numa , numb){
				console.log("sum-->this",this);
				return numa * numb;
			}
			
			
			function showMSG(){
				console.log(this)
				alert('提示信息')
			}
			
			//参数默认值
			function showPersonInfo(name , age ,address='未知'){
				console.log("姓名"+name+"  ,年龄"+age+"  家庭住址:"+address)
			}
		
			
			
			
			cal(10, 20)
			cal2(10, 20,30);
			calArguments(10,20,20);
			let result  = sum(2,6);
			console.log("result",result);
			
			//延迟执行
			// setTimeout(function(){
				
			// 	//绑定 this
			// 	showMSG.call('绑定this对象')
				
			// },3000)
			
			showPersonInfo("张飞",50,"河南")
			showPersonInfo("刘备",40)
			
			
			// console.error("error","error");
			// console.info("info","info");
			
			
			
			
			//箭头函数
			//函数简写
			let sayHi2 =   ()=>{
				//没有自己的 this
				console.log("this",this)
				console.log('sayHI---')
			}
			sayHi2.call({})
					
			
			
			let sumNums = (numa, numb)=>{  return numa+numb    }
			
			// let doubleNums = (numa)=>{  return numa * 2 }
			//如果是一个参数，小可以不写
			// let doubleNums = numa=>{  return numa * 2 }
			
		
			//函数体，只有一个运表达式，大括号可以不写，表格式的结果作为return返回
			let doubleNums = numa=>  numa * 2
			
			
			console.log("sumNums(10,20)",sumNums(10,20))
			console.log("doubleNums(10)",doubleNums(10))
			
		</script>
	</head>
	<body>
		<h3>请打开浏览器控制台，观察结果</h3>
		
		
		<button onclick="showMSG()">普通按钮</button>
	</body>
</html>